//package com.product.system.controller;
//
//import cn.hutool.json.JSONUtil;
//import com.product.system.utils.Result;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.net.*;
//
//@RestController
//public class WeatherController {
//
//    @Value("${juhe.api.key}")
//    private String apiKey;
//
//    @GetMapping("/weather")
//    public Result weather(String type) throws IOException {
//        String url = "http://apis.juhe.cn/simpleWeather/query?city="+type+"&"+"&key="+apiKey;
//        try {
//            URL apiUrl = new URL(url);
//            HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
//            connection.setRequestMethod("GET");
//
//            int responseCode = connection.getResponseCode();
//            if (responseCode==200){
//            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
//            String line;
//            StringBuilder response = new StringBuilder();
//            while ((line = reader.readLine())!=null){
//                response.append(line);
//            }
//            reader.close();
////            String respons = JSONUtil.toJsonStr(response);
//        //在这里处理获取到的天气数据
//
////                System.out.println(response.toString());
//                return Result.success(response.toString());
//            }else {
//                return Result.fail("请求失败，响应码:"+responseCode);
//            }
//        }catch (IOException e){
//            e.printStackTrace();
//            return Result.fail("获取天气数据报错");
//        }
//
//    }
//}
